﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using System.IO;
using DigiLib;

public partial class Administrator_Controls_HomeLinkEdit : Admin_Controls_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
        {
            loadData();
        }
    }
    protected void loadData()
    {
        try
        {
            DataSet objDS = new DataSet();
            objDS.ReadXml(Server.MapPath("~/slide.xml"));
            DataRow drow = objDS.Tables[0].Rows[Id - 1];
            txtName.Text = drow["TITLE"].ToString();
            txtLink.Text = drow["LINK"].ToString();
            ctImages.Src = "http://"+HttpContext.Current.Request.Url.Host + "/upload/" + drow["IMAGE"].ToString();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi xảy ra !<br />" + ex.Message);
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            DataSet objDS = new DataSet();
            objDS.ReadXml(Server.MapPath("~/slide.xml"));
            DataRow drow = objDS.Tables[0].Rows[Id - 1];
            string name = txtName.Text.Trim();
            string link = txtLink.Text.Trim();
            string filename = base.Upload("homelink", string.Empty, fupThumb, divMessage, false);
            if (string.IsNullOrEmpty(filename))
                filename = drow["IMAGE"].ToString();
            drow["TITLE"] = name;
            drow["LINK"] = link;
            drow["IMAGE"] = "http://" + HttpContext.Current.Request.Url.Host + "/upload/" + filename;
            objDS.WriteXml(Server.MapPath("~/slide.xml"));
            divMessage.InnerHtml = MessageBox.Success("Hệ Thống", "Cập nhật thành công!");
            Response.Redirect("default.aspx?control=homelink");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi xảy ra !<br />" + ex.Message);
        }
    }
}
